<?php
class KqBdsController extends AppController {

	var $name = 'KqBds';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->KqBd->recursive = 0;
		$this->set('kqBds', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid KqBd.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('kqBd', $this->KqBd->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->KqBd->create();
			if ($this->KqBd->save($this->data)) {
				$this->Session->setFlash(__('The KqBd has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The KqBd could not be saved. Please, try again.', true));
			}
		}
		$doituongs = $this->KqBd->Doituong->find('list',array('fields'=>array('Doituong.id','TEN_DT')));
		$pDtBds = $this->KqBd->PDtBd->find('list');
		//$doituongs = $this->KqBd->Doituong->find('list');
		$this->set(compact('pDtBds', 'doituongs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid KqBd', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->KqBd->save($this->data)) {
				$this->Session->setFlash(__('The KqBd has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The KqBd could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->KqBd->read(null, $id);
		}
		$pDtBds = $this->KqBd->PDtBd->find('list');
		$doituongs = $this->KqBd->Doituong->find('list');
		$this->set(compact('pDtBds','doituongs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for KqBd', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->KqBd->del($id)) {
			$this->Session->setFlash(__('KqBd deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}


}
?>